﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MockupDesigner.AppItems;
using System.Collections.ObjectModel;

namespace MockupDesigner.Dialogs
{
    /// <summary>
    /// Interaction logic for AddControlToToolboxWindow.xaml
    /// </summary>
    public partial class AddControlToToolboxWindow : Window
    {
        public AddControlToToolboxWindow()
        {
            InitializeComponent();
            ToolboxLB.ItemsSource = toolboxes;
        }

        private ObservableCollection<CustomToolbox> toolboxes = new ObservableCollection<CustomToolbox>();
        public ObservableCollection<CustomToolbox> Toolboxes
        {
            get { return toolboxes; }
        }

        public string ControlToolTip
        {
            get { return ToolTipTB.Text; }
        }

        public IList<CustomToolbox> SelectedToolboxes
        {
            get { return new List<CustomToolbox>(ToolboxLB.SelectedItems.OfType<CustomToolbox>()); }
        }

        private void CreateBT_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(NewToolBoxTB.Text) || (Toolboxes.Count(tb => tb.ToolboxName == NewToolBoxTB.Text) > 0))
            {
                MessageBox.Show(this, "No name given or a toolbox with this name already exists", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            Toolboxes.Add(new CustomToolbox() { ToolboxName = NewToolBoxTB.Text });
        }

        private void OkBT_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedToolboxes.Count == 0)
            {
                MessageBox.Show("No Toolbox Selected", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            this.DialogResult = true;
        }
    }
}
